package com.jx.controller.admin.system;

import com.jx.common.result.AjaxResult;
import com.jx.pojo.entity.system.Menu;
import com.jx.pojo.po.system.MenuPO;
import com.jx.pojo.po.system.MenuTree;
import com.jx.pojo.vo.system.MenuVO;
import com.jx.service.system.MenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单 相关接口
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    /**
     * 获取菜单列表
     */
    @GetMapping("/list")
    public AjaxResult list(MenuVO query) {
        List<MenuPO> list = menuService.listMenu(query);
        return AjaxResult.success(list);
    }

    /**
     * 保存菜单
     */
    @PostMapping("/save")
    public AjaxResult saveMenu(@RequestBody Menu menu) {
        menuService.saveMenu(menu);
        return AjaxResult.success("菜单保存成功");
    }

    /**
     * 根据id删除菜单
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(@RequestParam Integer id) {
        menuService.removeById(id);
        return AjaxResult.success("菜单删除成功");
    }

    /**
     * 根据id获取菜单详情
     */
    @GetMapping("/getById")
    public AjaxResult getById(@RequestParam Integer id) {
        Menu menu = menuService.getById(id);
        return AjaxResult.success(menu);
    }

    /**
     * 获取目录列表
     */
    @GetMapping("/getDirList")
    public AjaxResult getDirList() {
        List<Object> result = menuService.getDirList();
        return AjaxResult.success(result);
    }

    /**
     * 获取菜单树
     */
    @GetMapping("/getMenuTree")
    public AjaxResult getMenuTree() {
        List<MenuTree> result =  menuService.getMenuTree();
        return AjaxResult.success(result);
    }


}
